package com.efuture.servlet.serveletcontext;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * @description: 获取服务器(tomcat)文件的真实路径
 * @author zhaoshanshan
 * @date 2021/10/3 3:11 下午
 * @version 1.0
 */
@WebServlet("/GetFileRealpath")
public class GetFileRealpath extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext context = this.getServletContext();
        //获取test1.txt路径
        String test1Path = context.getRealPath("/WEB-INF/classes/test1.txt");
        System.out.println(test1Path);
        //获取test2.txt路径
        String test2Path = context.getRealPath("/text2.txt");
        System.out.println(test2Path);
        //获取test1.txt
        String test3Path = context.getRealPath("/WEB-INF/test3.txt");
        System.out.println(test3Path);


    }
}
